/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package xhserver;

/**
 *
 * @author Tri
 */
import com.google.gson.*;

public class JSONParser {
    private static JSONParser instance = null;
    private Gson m_gson;
    private JSONParser() {
        m_gson = new Gson();
    }
    
    public static JSONParser getInstance() {
        if(instance == null) {
            instance = new JSONParser();
        }
        return instance;
    }
    
    public static void destroyInstance() {
        instance = null;
    }
    
    public XHMessage fromJSON(String jsonString) {
        XHMessage msg = m_gson.fromJson(jsonString, XHMessage.class);
        return msg;
    }
    
    public String toJSON(Object obj) {
        return m_gson.toJson(obj);
    }
}
